familypediawikiaorg-20200214-history
User blog:Phlox/Converting tables into templates transcludable into Semantic Forms
Semantic Forms documentation states that pages can be transcluded in forms. This is a great boon for templates to modularize the creation of forms, in particular complex table layouts and elements, or for internationalizing forms. Due to the illegibility of the required format, it is best to test and create the code in a working form before converting it into the transcludable format. Manual method * convert table "|" pipes to * convert braces and bars of forms elements: ** } -> }}} ** convert forms "|" pipes to | (Actually, converting the bars is not necessary if you aren't putting any conditionals (#if functions) in the template. ) The trick is not to convert any bars inside templates, conditionals, links, or Images. Stay sharp. You miss one and you may have to do the whole bloody thing over. Automated approach With Word, copy and paste the following code into your macros (tools.macro.macros.visualbasic editor), paste after last macro. Follow instructions for the three steps in the comments at the start of each macro. This will create a largely unintelligible/ untestable transcluded table. With some practice, it is possible to understand how to debug them, but it is annoying. Sub formTableConvertStep1() ' ' Step1 run this word macro once on the document ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "|-" .Replacement.Text = " -" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "|}^p" .Replacement.Text = " }^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "{|^p" .Replacement.Text = " ^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p|" .Replacement.Text = "^p " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "||" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub Sub formTableConvertStep2() ' ' Step2 ' (Assign it to a key key) ' Go to the first line of the file & run this macro repeatedly line by line. ' Keep an eye out for legal bars in: ' * conditionals / functions / links / Image: lines ' * two fields in a single line, or ' * table bars following a } ' Selection.HomeKey Unit:=wdLine Selection.EndKey Unit:=wdLine, Extend:=wdExtend Selection.Find.ClearFormatting With Selection.Find .Text = "field" .Forward = False .Wrap = False .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.MoveLeft Unit:=wdCharacter, Count:=1 Selection.HomeKey Unit:=wdLine, Extend:=wdExtend Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "|" .Replacement.Text = " " .Forward = False .Wrap = False .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.MoveDown Unit:=wdLine, Count:=1 End Sub Sub formTableConvertStep3() ' ' formTableConvertStep3 Macro ' Step3- (Run only after table elements have been converted to use ) ' Assign to a key, begin at start of file, run repeatedly ' Selection.Find.ClearFormatting With Selection.Find .Text = " }" .Forward = True .Wrap = False .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.TypeParagraph Selection.TypeText Text:="}}}" Selection.MoveUp Unit:=wdLine, Count:=1 Selection.HomeKey Unit:=wdLine Selection.EndKey Unit:=wdLine, Extend:=wdExtend Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "|" .Replacement.Text = "|" .Forward = True .Wrap = False .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.EndKey Unit:=wdLine Selection.Delete Unit:=wdCharacter, Count:=1 Selection.Find.ClearFormatting With Selection.Find .Text = "{" .Forward = False .Wrap = False .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.HomeKey Unit:=wdLine Selection.TypeBackspace End Sub 05:27, 9 July 2009 (UTC) Category:Blog posts Category:SMW documentation